<?php
/**
 * Nadëb (Makú-Nadëb)
 * 
 * @author     Mateus Martins <mateusweb@gmail.com>
 * @copyright  Copyright 2010 mateusweb.com.br
 * @license    http://www.gnu.org/licenses/gpl.html | GPL
 * @package    Nadeb
 * @version    1.0.0
 */


/**
 * Class Nadeb_Report_Filters_Select
 * 
 * 
 * @category   Nadeb
 * @package    Nadeb_Report_Filters_Select
 * @copyright  Copyright 2010 mateusweb.com.br
 * @license    http://www.gnu.org/licenses/gpl.html | GPL
 */
abstract class Nadeb_Report_Filters_Select
{
	public static function get_xhtml($_filtersConfigs)
	{
		
		$db = Zend_Registry::get("db");
		$db->setFetchMode(Zend_Db::FETCH_ASSOC);
		
		$data = $db->fetchAll( "SELECT " . $_filtersConfigs['target'] . " FROM " . $_filtersConfigs['table'] . " GROUP BY " . $_filtersConfigs['target'] . " ORDER BY " .$_filtersConfigs['target'] . " ASC" );
		
		$js = Nadeb_JScontroller::get_instance();
		$js->JSInstance = "admin_filterSelect";
		
		$sqlFilters = new Zend_Session_Namespace();
		$sqlFilters->selectColumn = $_filtersConfigs['column'];
		
		$gd  = $sqlFilters->querySelect ? "\t\t\t<div class=\"selectFilters selected\">\n" : "\t\t\t<div class=\"selectFilters\">\n";
		$gd .= "\t\t\t\t<p class=\"fechar\"><a class=\"cancel_filters\" href=\"filterCancel/type/select\"> X </a></p>\n";
	    $gd .= "\t\t\t\t<p>\n";
		$gd .= "\t\t\t\t\tSelecione: <select id=\"select_filter\" name=\"select_filter\">\n";
		
		$gd .= "\t\t\t\t\t\t<option>" . strtoupper($sqlFilters->select_filter) . "</option>\n";
		
		foreach ( $data as $key => $value ) 
		{
			$val = $value[$_filtersConfigs['target']];
			$gd .= "\t\t\t\t\t\t<option value=\"$val\">$val</option>\n";
		}
		
		$gd .= "\t\t\t\t\t</select>\n";
		$gd .= "\t\t\t\t</p>\n";
		$gd .= "\t\t\t</div>\n";
		
		return $gd;
	}
	
	public static function save_sql($_params)
	{
		$sqlFilters                    = new Zend_Session_Namespace();
		$sqlFilters->querySelect       = $sqlFilters->selectColumn . " = '" . $_params['select_filter'] . "'";
		$sqlFilters->select_filter     = $_params['select_filter'];
	}
	
	public static function cancel_sql($_params)
	{
		$sqlFilters                     = new Zend_Session_Namespace();
		$sqlFilters->querySelect        = null;
		$sqlFilters->select_filter      = null;
		$sqlFilters->selectColumn       = null;
	}
	
	public static function get_sql()
	{
		$sqlFilters = new Zend_Session_Namespace();
		
		return $sqlFilters->querySelect;
	}
}
